package com.yanqu.road.dao.impl.activity.operamask;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.operamask.config.OperaMaskSceneConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class OperaMaskSceneConfigDaoImpl extends TempDao {

    private static String getOperaMaskSceneConfigSql = "select * from `t_s_opera_scene` where `activityId`=?";

    public Map<Integer, OperaMaskSceneConfig> getOperaMaskSceneConfigMap(int activityId) {
        Map<Integer, OperaMaskSceneConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getOperaMaskSceneConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                OperaMaskSceneConfig operaMaskSceneConfig = new OperaMaskSceneConfig();
                operaMaskSceneConfig.setActivityId(rs.getInt("activityId"));
                operaMaskSceneConfig.setSceneId(rs.getInt("sceneId"));
                operaMaskSceneConfig.setUnlock(rs.getString("unlock"));
                operaMaskSceneConfig.setUnlockSkills(rs.getString("unlockSkills"));
                operaMaskSceneConfig.setPaintBox(rs.getString("paintBox"));
                operaMaskSceneConfig.setStepNum(rs.getInt("stepNum"));
                operaMaskSceneConfig.setAssessLimit(rs.getString("assessLimit"));
                operaMaskSceneConfig.setEffectParam(rs.getString("effectParam"));
                operaMaskSceneConfig.setResId(rs.getInt("resId"));
                operaMaskSceneConfig.setDefaultList(rs.getString("defaultList"));
                operaMaskSceneConfig.setSkillRating(rs.getString("skillRating"));
                operaMaskSceneConfig.setReward(rs.getString("reward"));
                map.put(operaMaskSceneConfig.getSceneId(), operaMaskSceneConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
